<!-- 我的收藏 -->
<template>
	<view class="page-collect">
		<Work ref="work" v-if="form.type===1" :Heights='300'  :workList='workList' :total='total' :status="status" :userInfos="userInfo" text="暂无收藏"/>
		<Recruit v-if="form.type===0" :Heights='300' :resumeList='workList' :total='total' :status="status" :userInfos='userInfo' text="暂无收藏" :Type='0'/>
	</view>
</template>

<script>
	import Work from '@/components/home/work/index.vue'
	import Recruit from '@/components/home/recruit/index.vue'
	import * as user from '@/api/user.js'
	import * as index from '@/api/index.js'
	export default {
		components: {
			Work,
			Recruit
		},
		data(){
			return{
				status:'more',
				title: '', //分享标题
				imgage: '', //分享图片
				userInfo:{},
				form:{
					page:1,
					type:''
				},
				workList:[],
				total:-1,
				userInfo:{},
			}
		},
		onShow() {
			this.nameGetConfig()
		},
		onReachBottom() {
			this.form.page = this.form.page+1
			this.getCollectList()
		},
		onPullDownRefresh() {
			setTimeout(()=> {
			    uni.stopPullDownRefresh() 
				this.workList=[]
				this.form.page = 1
				this.getCollectList()
			}, 1000)
		},
		onLoad(){
			this.getType()
			this.getUserInfo()
			
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				user.wxForwardGetAward({type: 0}).then(res=>{
				})
			}
			return {
				title: this.title, //分享标题
				imageUrl: this.imgage,
				path: '/pages/home/index'
			}
		},
		methods:{
			// 获取分享图片
			nameGetConfig() {
				index.nameGetConfig({name:'wx_share_image,wx_share_title,resume_forward'}).then(res=>{
					this.imgage = res.data.wx_share_image
					this.title = res.data.wx_share_title
					if (uni.getStorageSync('shareType') == 1) {
						uni.showToast({
							icon: 'none',
							title: `查看需求已+${res.data.resume_forward}条,\n感谢您助力鱼台就业。`,
							duration: 2000
						});
						uni.removeStorageSync('shareType');
					}
				})
			},
			getType(){
				let type = uni.getStorageSync('Type')
				if(type == '0') {
					this.form.type = 1
				} else if (type == '1') {
					this.form.type = 0
				}
				this.$forceUpdate()
				this.getCollectList()
			},
			//获取列表
			getCollectList(){
				this.status='loading'
				user.getCollectList(this.form).then(res=>{
					this.workList.push(...res.data.data)
					this.total =res.data.total
					setTimeout(()=>{
						if(res.data.current_page<res.data.last_page){
							this.status='more'
						}
						else{
							this.status='noMore'
						}
					},200)
				})
				
			},
			//获取用户信息
			getUserInfo(){
				user.getUserInfo({type:this.form.type}).then(res=>{
					this.userInfo = res.data
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page-collect {
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
</style>
